<template>
    <div>
        <h1>登录</h1>
        <table class="table">
            <tbody>
                <tr>
                    <td>用户名</td>
                    <td><input type="text" v-model="data.MName"></td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td><input type="password" v-model="data.MPass"></td>
                </tr>


                <tr>
                    <td></td>
                    <td><input type="button" value="登录" @click="Deng"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';


const data = ref({
    "MId": 0,
  "MName": "",
  "MPass": "",
  "LeveId": 0,
  "MImg": "",
  "MAge": 0,
  "MState": true
})
const router = useRouter()
const Deng=()=>{
    if(data.value.MName==""){
        alert('用户名不能为空')
        return
    }
    if(data.value.MPass==""){
        alert('用户名不能为空')
        return
    }

    axios.get('https://localhost:7174/api/Login/Deng',{params:data.value}).then(res=>{
        if(res.data.MId==-1){
            alert('用户不存在');
            return
        }
        else if(res.data.MId==-2){
            alert('登录失败，密码错误')
            return
        }
        else{
            alert('登陆成功')
            router.push({path:"/MemberShow"})
        }
    })


}


</script>

<style scoped>

</style>